﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Text;

namespace DBUtil
{
    public interface IDBHelper
    {

        /// <summary>
        /// 插入对象数据
        /// </summary>
        /// <typeparam name="M">对象类型</typeparam>
        /// <param name="model">对象</param>
        /// <param name="excludeColName">要排除的属性列名</param>
        /// <returns>是否插入成功</returns>
        bool Insert<M>(M model, params string[] excludeColName);



        /// <summary>
        /// 更新对象数据
        /// </summary>
        /// <typeparam name="M">对象类型</typeparam>
        /// <param name="model">对象</param>
        /// <param name="excludeColName">要排除的属性列名</param>
        /// <returns>是否更新成功</returns>
        bool Update<M>(M model, params string[] excludeColName);


        /// <summary>
        /// 根据 Id的值删除数据
        /// </summary>
        /// <typeparam name="M">Model类型</typeparam>
        /// <param name="Id">Id值</param>
        /// <returns></returns>
        int Delete<M>(string Id);


        /// <summary>
        /// 根据 列、值批量删除数据
        /// </summary>
        /// <typeparam name="M">Model类型</typeparam>
        /// <param name="columnName">列名</param>
        /// <param name="value">列值</param>
        /// <returns>受影响行数</returns>
        int DeleteBatch<M>(string columnName, object value);




        /// <summary>
        /// 根据 Id的值 更新 列值
        /// </summary>
        /// <typeparam name="M">Model类型</typeparam>
        /// <param name="Id">Id值</param>
        /// <param name="ht">待更新数据</param>
        /// <returns>受影响行数</returns>
        int Update<M>(string Id, Hashtable ht);

        /// <summary>
        /// 根据 列名与值 批量更新 数据
        /// </summary>
        /// <typeparam name="M">Model类型</typeparam>
        /// <param name="columnName">列名</param>
        /// <param name="value">列值</param>
        /// <param name="ht">待更新数据</param>
        /// <returns>受影响行数</returns>
        int UpdateBatch<M>(string columnName, object value, Hashtable ht);



        /// <summary>
        /// 返回单个值
        /// </summary>
        /// <typeparam name="T">指定返回类型</typeparam>
        /// <param name="strSql">SQL语句</param>
        /// <param name="paras">参数化 数组</param>
        /// <returns>指定类型的值</returns>
        T GetSingle<T>(string strSql, params DbParameter[] paras);


        /// <summary>
        /// 查询获取DataTable数据
        /// </summary>
        /// <param name="strSql">查询语句</param>
        /// <param name="paras">参数化 数组</param>
        /// <returns>DataTable数据</returns>
        DataTable ExecuteDataTable(string strSql, params DbParameter[] paras);

        /// <summary>
        /// 查询获取List集合对象
        /// </summary>
        /// <typeparam name="M">对象类型</typeparam>
        /// <param name="strSql">查询语句</param>
        /// <param name="paras">参数化 数组</param>
        /// <returns>List集合对象</returns>
        List<M> GetList<M>(string strSql, params DbParameter[] paras);


        /// <summary>
        /// 通过 存储过程或查询语句 执行分页查询
        /// </summary>
        /// <param name="pageSize">每页数据量</param>
        /// <param name="currentPage">当前页，自动默认为为1</param>
        /// <param name="fields">查询字段，可以用 * 表示所有</param>
        /// <param name="orderString">排序字段 + asc/desc</param>
        /// <param name="whereString">不包含‘where’的字符串</param>
        /// <param name="tablename">表名，或者为查询得出的 子表 ，子表查询sql需要括号括起来，并指定新表名</param>
        /// <param name="count">返回总条数</param>
        /// <returns></returns>
        DataTable GetDataTableByPager(int pageSize, int currentPage, string fields, string orderString, string whereString, string tablename, out int totalCount);
    }
}
